Skip to content

Conversation

@vinser52
Copy link
Contributor

@vinser52 vinser52 commented Mar 31, 2025

This PR optimizes global object singleton creation by removing the getOrCreate() from the hot path for most of the global objects.

  • getOrCreate() method locks mutex on every call
  • We cannot just use the C++11 way of creating static singleton variables inside corresponding methods because we need to control the destruction order of global objects. Therefore, we use static variables to cache the result of the getOrCreate() method so that it calls only once per global object.
  • The optimization is not done for the GlobalHandler::getPlatformToDefaultContextCache method because there are public methods of the GlobalHandler that can set the MPlatformToDefaultContextCache back to nullptr.

@vinser52 vinser52 requested a review from a team as a code owner March 31, 2025 13:28
@vinser52 vinser52 requested a review from uditagarwal97 March 31, 2025 13:28
@vinser52 vinser52 changed the title Optimize creation of global objects in GlobalHandler [SYCL] Optimize creation of global objects in GlobalHandler Mar 31, 2025
@vinser52 vinser52 requested a review from sergey-semenov March 31, 2025 13:29
@sergey-semenov
Copy link
Contributor

LGTM.

The optimization is not done for the GlobalHandler::getPlatformToDefaultContextCache method because ther are public methods of the GlobalHandler that can set the MPlatformToDefaultContextCache back to nullptr.

I suggest adding this as a comment.

@vinser52
Copy link
Contributor Author

The optimization is not done for the GlobalHandler::getPlatformToDefaultContextCache method because ther are public methods of the GlobalHandler that can set the MPlatformToDefaultContextCache back to nullptr.

I suggest adding this as a comment.

@sergey-semenov Done

@uditagarwal97 uditagarwal97 merged commit f41f953 into intel:sycl Apr 1, 2025
22 checks passed
@vinser52 vinser52 deleted the optimize_global_handler branch April 4, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants